/**  
 * All rights Reserved, Designed By Android_Robot   
 * @Title:  MyMessageActivity.java   
 * @Package com.jiyi.activity   
 * @Description:    TODO(用一句话描述该文件做什么)   
 * @author: HYM     
 * @date:   2017-7-20 下午2:58:41   
 * @version V1.0     
 */
package com.jiyi.activity;

import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.hyphenate.easeui.EaseConstant;
import com.jiyi.adapter.recyclerview.CommonAdapter;
import com.jiyi.adapter.recyclerview.base.ViewHolder;
import com.jiyi.bean.message.Message;
import com.jiyi.common.StringInterface;
import com.jiyi.common.VolleyRequest;
import com.jiyi.easemob.util.ClouldChatType;
import com.jiyi.easemob.view.EasemobChatActivity;
import com.jiyi.event.HaoYouListEvent;
import com.jiyi.event.MessageListEvent;
import com.jiyi.event.QunZuListEvent;
import com.jiyi.event.RefreshHintEvent;
import com.jiyi.inteface.DeletePopInterface;
import com.jiyi.inteface.WebApi;
import com.jiyi.service.MessageService;
import com.jiyi.service.impl.MessageServiceImpl;
import com.jiyi.view.DeletePopView;
import com.swift.base.ActivityBase;
import com.swift.maintenance.R;
import com.swift.maintenance.base.AppConfig;
import com.swift.maintenance.utils.ToastUtil;
import com.swift.maintenance.utils.UserInfoUtil;
import com.swift.utils.DialogTool;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @ClassName: MyMessageActivity
 * @Description:TODO(这里用一句话描述这个类的作用)
 * @author: HYM
 * @date: 2017-7-20 下午2:58:41
 * 
 */
public class MyMessageActivity extends ActivityBase implements
		OnRefreshListener, DeletePopInterface {

	@BindView(R.id.tvBack)
	TextView tvBack;
	@BindView(R.id.tvTitle)
	TextView tvTitle;
	@BindView(R.id.tvSearch)
	TextView tvSearch;

	@BindView(R.id.refreshLayout)
	SwipeRefreshLayout refreshLayout;
	@BindView(R.id.mainList)
	RecyclerView mainList;

	CommonAdapter<Message> adapter;
	List<Message> myMessageList = new ArrayList<Message>();

	// 加载进度条
	Dialog dialog;
	// 消息服务层
	MessageService mMessageService;

	// 删除对话框
	DeletePopView mDeletePopView;
	// 要删除的消息位置
	int deletePosition = -1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_my_message);
		ButterKnife.bind(this);
		init();
	}

	private void init() {
		setTop();
		mMessageService = new MessageServiceImpl();
		setAdater();
		getData();
		EventBus.getDefault().register(this);
		mDeletePopView = new DeletePopView(this, this);
	}

	@Subscribe
	public void onMessageListEvent(MessageListEvent messageListEvent) {
		int type = messageListEvent.type;
		switch (type) {
		case MessageListEvent.MY_MESSAGE:
			getData();
			break;

		default:
			break;
		}
	}

	@Override
	protected void onDestroy() {
		EventBus.getDefault().unregister(this);
		hideDialog(dialog);
		super.onDestroy();
	}

	/**
	 * @author: HYM
	 * @Title: getData
	 * @Description: TODO(这里用一句话描述这个方法的作用) void
	 * @date: 2017-7-20
	 */
	private void getData() {
		// String account = ApplicationBase.LocalData.getString("input.user",
		// "");
		// String password = ApplicationBase.LocalData.getString("password",
		// "");
		//
		// Map<String, String> params = new HashMap<String, String>();
		// params.put("account", account);
		// params.put("password", password);
		//
		// dialog = showDialog(dialog);
		// VolleyRequest.StringRequestPost(this, WebApi.MY_MESSAGE, "", params,
		// new StringInterface(this) {
		//
		// @Override
		// public void stringSuccess(String result) {
		// try {
		// JSONObject obj = new JSONObject(result);
		// String status = obj.getString("status");
		// String info = obj.getString("info");
		// if (status.equals("200")) {
		// String data = obj.getString("data");
		// List<MyMessageBean> temp = new Gson().fromJson(
		// data,
		// new TypeToken<List<MyMessageBean>>() {
		// }.getType());
		// if (temp != null) {
		// myMessageList.clear();
		// myMessageList.addAll(temp);
		// adapter.notifyDataSetChanged();
		// }
		// } else {
		// ToastUtil.getInstances().showMsg(info);
		// }
		// } catch (JSONException e) {
		// e.printStackTrace();
		// } finally {
		// hideDialog(dialog);
		// refreshLayout.setRefreshing(false);
		// }
		// }
		//
		// @Override
		// public void stringError(VolleyError error) {
		// hideDialog(dialog);
		// refreshLayout.setRefreshing(false);
		// ToastUtil.getInstances().showMsg(R.string.err_http_response);
		// }
		// });

		List<Message> temp = mMessageService.getMsgByAccount(UserInfoUtil
				.getCurrentUserAccount());
		myMessageList.clear();
		myMessageList.addAll(temp);
		adapter.notifyDataSetChanged();
		refreshLayout.setRefreshing(false);
	}

	private void setTop() {
		tvBack.setText("");
		tvTitle.setText("消息");
		tvSearch.setVisibility(View.GONE);
	}

	private void setAdater() {
		refreshLayout.setColorSchemeColors(Color.RED, Color.YELLOW, Color.BLUE,
				Color.GREEN);
		refreshLayout.setOnRefreshListener(this);

		// adapter = new MultiItemTypeAdapter(this,myMessageList);
		// adapter.addItemViewDelegate(new HaoYouShenHeItemDelagate());

		// MyMessageBean messageBean = new MyMessageBean();
		// messageBean.setTitle("s");
		// messageBean.setContent("c");
		// myMessageList.add(messageBean);
		// MyMessageBean messageBean2 = new MyMessageBean();
		// messageBean2.setTitle("s");
		// messageBean2.setContent("c");
		// myMessageList.add(messageBean2);

		//
		// adapter = new CommonAdapter<MyMessageBean>(this, myMessageList,
		// R.layout.item_haoyou_shenhe) {
		//
		// @Override
		// public void convert(ViewHolder holder, MyMessageBean t) {
		// holder.setImage(R.id.ivLogo,
		// "http://test.jyfire.cn/Public/platform/images/icon-default.png");
		// holder.setText(R.id.tvTitle, t.getTitle());
		// holder.setText(R.id.tvContent, t.getContent());
		// }
		// };

		// 设置布局管理器
		mainList.setLayoutManager(new LinearLayoutManager(this));
		adapter = new CommonAdapter<Message>(this, R.layout.item_haoyou_shenhe,
				myMessageList) {
			@Override
			protected void convert(ViewHolder holder, final Message t,
					final int position) {
				holder.setImage(R.id.ivLogo, t.getMsgIcon());
				holder.setVisible(R.id.iv_msg_hint, !t.getIsReaded());
				holder.setText(R.id.tvTitle, t.getMsgTitle());
				holder.setEaseMobText(R.id.tvContent, t.getMsgContent());
				holder.setText(R.id.tvCreateDate, t.getCreateDate());
				holder.setOnClickListener(R.id.llRoot, new OnClickListener() {

					@Override
					public void onClick(View v) {
						handleMessage(t);
					}
				});
				holder.setOnLongClickListener(R.id.llRoot,
						new OnLongClickListener() {

							@Override
							public boolean onLongClick(View v) {
								deletePosition = position;
								mDeletePopView.showPopWindow();
								return true;
							}
						});
			}
		};
		mainList.setAdapter(adapter);
	}

	// private void setAdater() {
	// // 设置布局管理器
	// mainList.setLayoutManager(new LinearLayoutManager(this));
	// // 添加分割线
	// mainList.addItemDecoration(new DividerItemDecoration(this,
	// DividerItemDecoration.VERTICAL_LIST, getResources()
	// .getDrawable(R.drawable.drvice_5)));
	// // 初始化适配器
	// adapter = new CommonAdapter<MyMessageBean>(this,
	// R.layout.item_haoyou_shenhe, myMessageList) {
	// @Override
	// protected void convert(
	// com.jiyi.adapter.recyclerview.base.ViewHolder holder,
	// final MyMessageBean t, int position) {
	// holder.setImage(R.id.ivLogo,
	// "http://test.jyfire.cn/Public/platform/images/icon-default.png");
	// holder.setText(R.id.tvTitle, t.getTitle());
	// holder.setText(R.id.tvContent, t.getContent());
	// }
	// };
	// mainList.setAdapter(adapter);
	// }

	@OnClick({ R.id.tvBack })
	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.tvBack:
			finish();
			break;
		default:
			break;
		}
	}

	@Override
	public void onRefresh() {
		getData();
	}

	void doAgreeHaoYou(final long pkid, String id) {
		Map<String, String> params = new HashMap<String, String>();
		params.put(AppConfig.ACCESS_TOKEN,
				UserInfoUtil.getCurrentUserAccessToken());
		params.put("id", id);
		dialog = showDialog(dialog);
		VolleyRequest.StringRequestPost(this, WebApi.AGREE_HAOYOU, "", params,
				new StringInterface(this) {

					@Override
					public void stringSuccess(String result) {
						try {
							JSONObject obj = new JSONObject(result);
							String status = obj.getString("status");
							String info = obj.getString("info");
							if (status.equals("200")) {
								ToastUtil.getInstances().showMsg(info);
								EventBus.getDefault()
										.post(new HaoYouListEvent(
												HaoYouListEvent.MY_HAOYOU_FRAGMENT));
								setHandle(pkid);
							} else {
								ToastUtil.getInstances().showMsg(info);
								if (checkSkin(info)) {
									setHandle(pkid);
								}
							}
						} catch (JSONException e) {
							e.printStackTrace();
						} finally {
							hideDialog(dialog);
						}
					}

					@Override
					public void stringError(VolleyError error) {
						hideDialog(dialog);
						ToastUtil.getInstances().showMsg(
								R.string.err_http_response);
					}
				});
	}

	void doDisAgreeHaoYou(final long pkid, String id) {
		Map<String, String> params = new HashMap<String, String>();
		params.put(AppConfig.ACCESS_TOKEN,
				UserInfoUtil.getCurrentUserAccessToken());
		params.put("id", id);
		dialog = showDialog(dialog);
		VolleyRequest.StringRequestPost(this, WebApi.DIS_AGREE_HAOYOU, "",
				params, new StringInterface(this) {

					@Override
					public void stringSuccess(String result) {
						try {
							JSONObject obj = new JSONObject(result);
							String status = obj.getString("status");
							String info = obj.getString("info");
							if (status.equals("200")) {
								ToastUtil.getInstances().showMsg(info);
								setHandle(pkid);
							} else {
								ToastUtil.getInstances().showMsg(info);
								if (checkSkin(info)) {
									setHandle(pkid);
								}
							}
						} catch (JSONException e) {
							e.printStackTrace();
						} finally {
							hideDialog(dialog);
						}
					}

					@Override
					public void stringError(VolleyError error) {
						hideDialog(dialog);
						ToastUtil.getInstances().showMsg(
								R.string.err_http_response);
					}
				});
	}

	void doAgreeQunZu(final long pkid, String id, String type) {
		Map<String, String> params = new HashMap<String, String>();
		params.put(AppConfig.ACCESS_TOKEN,
				UserInfoUtil.getCurrentUserAccessToken());
		params.put("id", id);
		params.put("type", type);
		dialog = showDialog(dialog);
		VolleyRequest.StringRequestPost(this, WebApi.AGREE_QUNZU_APPLY, "",
				params, new StringInterface(this) {

					@Override
					public void stringSuccess(String result) {
						try {
							JSONObject obj = new JSONObject(result);
							String status = obj.getString("status");
							String info = obj.getString("info");
							if (status.equals("200")) {
								ToastUtil.getInstances().showMsg(info);
								EventBus.getDefault()
										.post(new QunZuListEvent(
												QunZuListEvent.MY_QUNZU_FRAGMENT));
								setHandle(pkid);
							} else {
								ToastUtil.getInstances().showMsg(info);
								if (checkSkin(info)) {
									setHandle(pkid);
								}
							}
						} catch (JSONException e) {
							e.printStackTrace();
						} finally {
							hideDialog(dialog);
						}
					}

					@Override
					public void stringError(VolleyError error) {
						hideDialog(dialog);
						ToastUtil.getInstances().showMsg(
								R.string.err_http_response);
					}
				});
	}

	void doDisAgreeQunZu(final long pkid, String id, String type) {
		Map<String, String> params = new HashMap<String, String>();
		params.put(AppConfig.ACCESS_TOKEN,
				UserInfoUtil.getCurrentUserAccessToken());
		params.put("id", id);
		params.put("type", type);
		dialog = showDialog(dialog);
		VolleyRequest.StringRequestPost(this, WebApi.DIS_AGREE_QUNZU_APPLY, "",
				params, new StringInterface(this) {

					@Override
					public void stringSuccess(String result) {
						try {
							JSONObject obj = new JSONObject(result);
							String status = obj.getString("status");
							String info = obj.getString("info");
							if (status.equals("200")) {
								ToastUtil.getInstances().showMsg(info);
								setHandle(pkid);
							} else {
								ToastUtil.getInstances().showMsg(info);
								if (checkSkin(info)) {
									setHandle(pkid);
								}
							}
						} catch (JSONException e) {
							e.printStackTrace();
						} finally {
							hideDialog(dialog);
						}
					}

					@Override
					public void stringError(VolleyError error) {
						hideDialog(dialog);
						ToastUtil.getInstances().showMsg(
								R.string.err_http_response);
					}
				});
	}

	/**
	 * @author: HYM
	 * @Title: doAgreeHire
	 * @Description: TODO(同意雇佣关系的审核)
	 * @param pkid
	 * @param id
	 *            void
	 * @date: 2017-10-16
	 */
	void doAgreeHire(final long pkid, String id) {
		Map<String, String> params = new HashMap<String, String>();
		params.put(AppConfig.ACCESS_TOKEN,
				UserInfoUtil.getCurrentUserAccessToken());
		params.put("id", id);
		dialog = showDialog(dialog);
		VolleyRequest.StringRequestPost(this, WebApi.OWNER_AGREE_HIRE, "",
				params, new StringInterface(this) {

					@Override
					public void stringSuccess(String result) {
						try {
							JSONObject obj = new JSONObject(result);
							String status = obj.getString("status");
							String info = obj.getString("info");
							if (status.equals("200")) {
								ToastUtil.getInstances().showMsg(info);
								setHandle(pkid);
							} else {
								ToastUtil.getInstances().showMsg(info);
								if (checkSkin(info)) {
									setHandle(pkid);
								}
							}
						} catch (JSONException e) {
							e.printStackTrace();
						} finally {
							hideDialog(dialog);
						}
					}

					@Override
					public void stringError(VolleyError error) {
						hideDialog(dialog);
						ToastUtil.getInstances().showMsg(
								R.string.err_http_response);
					}
				});
	}

	/**
	 * @author: HYM
	 * @Title: doAgreeHire
	 * @Description: TODO(不同意雇佣关系的审核)
	 * @param pkid
	 * @param id
	 *            void
	 * @date: 2017-10-16
	 */
	void doDisAgreeHire(final long pkid, String id) {
		Map<String, String> params = new HashMap<String, String>();
		params.put(AppConfig.ACCESS_TOKEN,
				UserInfoUtil.getCurrentUserAccessToken());
		params.put("id", id);
		dialog = showDialog(dialog);
		VolleyRequest.StringRequestPost(this, WebApi.OWNER_DISAGREE_HIRE, "",
				params, new StringInterface(this) {

					@Override
					public void stringSuccess(String result) {
						try {
							JSONObject obj = new JSONObject(result);
							String status = obj.getString("status");
							String info = obj.getString("info");
							if (status.equals("200")) {
								ToastUtil.getInstances().showMsg(info);
								setHandle(pkid);
							} else {
								ToastUtil.getInstances().showMsg(info);
								if (checkSkin(info)) {
									setHandle(pkid);
								}
							}
						} catch (JSONException e) {
							e.printStackTrace();
						} finally {
							hideDialog(dialog);
						}
					}

					@Override
					public void stringError(VolleyError error) {
						hideDialog(dialog);
						ToastUtil.getInstances().showMsg(
								R.string.err_http_response);
					}
				});
	}

	/**
	 * @author: HYM
	 * @Title: doAgreeHire
	 * @Description: TODO(同意解除雇佣关系的审核)
	 * @param pkid
	 * @param id
	 *            void
	 * @date: 2017-10-16
	 */
	void doAgreeDeleteHire(final long pkid, String id) {
		Map<String, String> params = new HashMap<String, String>();
		params.put(AppConfig.ACCESS_TOKEN,
				UserInfoUtil.getCurrentUserAccessToken());
		params.put("id", id);
		dialog = showDialog(dialog);
		VolleyRequest.StringRequestPost(this, WebApi.OWNER_AGREE_DELETE_HIRE,
				"", params, new StringInterface(this) {

					@Override
					public void stringSuccess(String result) {
						try {
							JSONObject obj = new JSONObject(result);
							String status = obj.getString("status");
							String info = obj.getString("info");
							if (status.equals("200")) {
								ToastUtil.getInstances().showMsg(info);
								setHandle(pkid);
							} else {
								ToastUtil.getInstances().showMsg(info);
								if (checkSkin(info)) {
									setHandle(pkid);
								}
							}
						} catch (JSONException e) {
							e.printStackTrace();
						} finally {
							hideDialog(dialog);
						}
					}

					@Override
					public void stringError(VolleyError error) {
						hideDialog(dialog);
						ToastUtil.getInstances().showMsg(
								R.string.err_http_response);
					}
				});
	}

	/**
	 * @author: HYM
	 * @Title: doAgreeHire
	 * @Description: TODO(不同意解除雇佣关系的审核)
	 * @param pkid
	 * @param id
	 *            void
	 * @date: 2017-10-16
	 */
	void doDisAgreeDeleteHire(final long pkid, String id) {
		Map<String, String> params = new HashMap<String, String>();
		params.put(AppConfig.ACCESS_TOKEN,
				UserInfoUtil.getCurrentUserAccessToken());
		params.put("id", id);
		dialog = showDialog(dialog);
		VolleyRequest.StringRequestPost(this,
				WebApi.OWNER_DISAGREE_DELETE_HIRE, "", params,
				new StringInterface(this) {

					@Override
					public void stringSuccess(String result) {
						try {
							JSONObject obj = new JSONObject(result);
							String status = obj.getString("status");
							String info = obj.getString("info");
							if (status.equals("200")) {
								ToastUtil.getInstances().showMsg(info);
								setHandle(pkid);
							} else {
								ToastUtil.getInstances().showMsg(info);
								if (checkSkin(info)) {
									setHandle(pkid);
								}
							}
						} catch (JSONException e) {
							e.printStackTrace();
						} finally {
							hideDialog(dialog);
						}
					}

					@Override
					public void stringError(VolleyError error) {
						hideDialog(dialog);
						ToastUtil.getInstances().showMsg(
								R.string.err_http_response);
					}
				});
	}

	/**
	 * @author: HYM
	 * @Title: handleByMessageType
	 * @Description: TODO(根据消息类型和消息归属类型处理动作)
	 * @ type
	 *            消息类型 1：群邀请成员消息 2：群解散通知 3：退群通知 4：申请入群通知 5：群聊天消息、6：申请好友 7: 好友聊天
	 *            8: 被移除群通知 9 : 同意被邀请入群 10: 入群通知 11.退出活动通知 12 取消活动通知
	 *            13维保向业主发起雇佣关系 14业主向维保公司发起雇佣关系申请 15 异常申报 16维保向业主发起解除雇佣关系
	 *            17业主向维保发起解除雇佣关系 18业主同意建立雇佣关系 19业主不同意建立雇佣关系
	 *            20业主同意维保发起的解除雇佣关系的申请 21业主不同意维保发起的解除雇佣关系的申请
	 * 
	 * @ attr_type
	 *            消息归属类型 1：群组 2：活动 3：好友 4：活动 5：话题 6：系统 7：吉友秀 8：商城 9：维保
	 * @date: 2017-7-21
	 */
	void handleMessage(final Message message) {
		// 如果已经操作过就不可再次操作
		if (message.getIsHandle()) {
			return;
		}
		switch (message.getBelongType()) {
		case 1:
			// 群组归属
			switch (message.getMsgType()) {
			case 1:
			case 4:
				// 群邀请成员消息
				// 申请入群通知
				DialogTool.createConfirmDialog(this, "提示", "是否同意?", "确定", "拒绝",
						new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								doAgreeQunZu(message.getId(),
										message.getMatchId(),
										message.getMsgType() + "");
								dialog.dismiss();
							}
						}, new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								doDisAgreeQunZu(message.getId(),
										message.getMatchId(),
										message.getMsgType() + "");
								dialog.dismiss();
							}
						}, DialogTool.NO_ICON).show();
				break;
			case 2:
			case 3:
			case 8:
			case 9:
			case 10:
				setRead(message.getId());
				break;
			case 5:
				Intent intent2 = new Intent(this, EasemobChatActivity.class);
				intent2.putExtra(ClouldChatType.INTENT_USER_PIC,
						message.getMsgIcon());
				intent2.putExtra("id", message.getSend_user_id());
				intent2.putExtra("name", message.getMsgTitle());
				intent2.putExtra("easemobgid", message.getSend_easemob_id());
				intent2.putExtra(ClouldChatType.INTENT_Group_Id,
						message.getSend_user_id());
				intent2.putExtra("easeMobChatType", EaseConstant.CHATTYPE_GROUP);
				startActivity(intent2);
				setRead(message.getId());
				break;
			}
			break;
		case 2:
			// 活动
			switch (message.getMsgType()) {
			case 11:
			case 12:
				setRead(message.getId());
				break;
			}
			break;
		case 3:
			// 好友归属
			switch (message.getMsgType()) {
			case 6:
				// 申请好友
				DialogTool.createConfirmDialog(this, "提示", "是否同意?", "确定", "拒绝",
						new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								doAgreeHaoYou(message.getId(),
										message.getMatchId());
								dialog.dismiss();
							}
						}, new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								doDisAgreeHaoYou(message.getId(),
										message.getMatchId());
								dialog.dismiss();
							}
						}, DialogTool.NO_ICON).show();
				break;
			case 7:
				// 好友聊天
				Intent intent2 = new Intent(this, EasemobChatActivity.class);
				intent2.putExtra(ClouldChatType.INTENT_USER_PIC,
						message.getMsgIcon());
				intent2.putExtra("id", message.getSend_user_id());
				intent2.putExtra("name", message.getMsgTitle());
				intent2.putExtra("easemobgid", message.getSend_easemob_id());
				intent2.putExtra(ClouldChatType.INTENT_Group_Id, "");
				intent2.putExtra("easeMobChatType",
						EaseConstant.CHATTYPE_SINGLE);
				startActivity(intent2);
				setRead(message.getId());
				break;
			}
			break;
		case 9:
			// 维保
			switch (message.getMsgType()) {
			case 13:
				// 维保向业主发起雇佣关系
				// 业主端审核雇佣关系
				DialogTool.createConfirmDialog(this, "提示", "是否同意?", "确定", "拒绝",
						new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								doAgreeHire(message.getId(),
										message.getMatchId());
								dialog.dismiss();
							}
						}, new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								doDisAgreeHire(message.getId(),
										message.getMatchId());
								dialog.dismiss();
							}
						}, DialogTool.NO_ICON).show();
				break;
			case 14:
				// 业主向维保公司发起雇佣关系申请 维保端收到的

				break;
			case 15:
				// 异常申报
			case 18:
				// 业主同意建立雇佣关系
			case 19:
				// 业主不同意建立雇佣关系
			case 20:
				// 业主同意维保发起的解除雇佣关系的申请
			case 21:
				// 业主不同意维保发起的解除雇佣关系的申请
				setRead(message.getId());
				break;
			case 16:
				DialogTool.createConfirmDialog(this, "提示", "是否同意?", "确定", "拒绝",
						new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								doAgreeDeleteHire(message.getId(),
										message.getMatchId());
								dialog.dismiss();
							}
						}, new DialogInterface.OnClickListener() {

							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								doDisAgreeDeleteHire(message.getId(),
										message.getMatchId());
								dialog.dismiss();
							}
						}, DialogTool.NO_ICON).show();
				break;
			case 17:

				break;
			}
			break;
		default:
			break;
		}
	}

	void setRead(long id) {
		mMessageService.setMsgReaded(id);
		EventBus.getDefault().post(new RefreshHintEvent(RefreshHintEvent.MIME));
		getData();
	}

	void setHandle(long id) {
		mMessageService.setMsgHandle(id);
		EventBus.getDefault().post(new RefreshHintEvent(RefreshHintEvent.MIME));
		getData();
	}

	@Override
	public void OnDeleteListener() {
		doDelete(myMessageList.get(deletePosition).getId());
	}

	/**
	 * <p>
	 * Title: OnCancleListener
	 * </p>
	 * <p>
	 * Description:
	 * </p>
	 * 
	 * @see DeletePopInterface#OnCancleListener()
	 */
	@Override
	public void OnCancleListener() {
		// TODO Auto-generated method stub

	}

	/**
	 * <p>
	 * Title: OnShowListener
	 * </p>
	 * <p>
	 * Description:
	 * </p>
	 * 
	 * @see DeletePopInterface#OnShowListener()
	 */
	@Override
	public void OnShowListener() {
		refreshLayout.setEnabled(false);
	}

	@Override
	public void OnHideListener() {
		refreshLayout.setEnabled(true);
		deletePosition = -1;
	}

	/**
	 * @author: HYM
	 * @Title: doDelete
	 * @Description: TODO(根据消息对象的id来删除)
	 * @param id
	 *            void
	 * @date: 2017-8-11
	 */
	void doDelete(long id) {
		mMessageService.deleteMsgByid(id);
		myMessageList.remove(deletePosition);
		adapter.notifyDataSetChanged();
		mDeletePopView.hidePopWindow();
		EventBus.getDefault().post(new RefreshHintEvent(RefreshHintEvent.MIME));
	}

	boolean checkSkin(String info) {
		if (info.contains("该事件已被处理过") || info.contains("id为空") || info.contains("没有该记录")) {
			return true;
		}
		return false;
	}
}
